package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.impl.DishServiceImpl;
import com.sky.vo.DishVO;
import com.sky.vo.PageResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/dish")
public class DishController {

    @Autowired
    private DishServiceImpl dishServiceImpl;

    @GetMapping("/page")
    public Result pageList(DishPageQueryDTO dishPageQueryDTO) {
         PageResultVO result = dishServiceImpl.pageList(dishPageQueryDTO);
         return Result.success(result);
    }

    @PostMapping
    public Result save(@RequestBody DishDTO dishDTO) {
        dishServiceImpl.save(dishDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        DishVO result = dishServiceImpl.getById(id);
        return Result.success(result);
    }

    @GetMapping("/list")
    public Result getByCategoryId(@RequestParam String categoryId) {
         List result = dishServiceImpl.getByCategoryId(categoryId);
         return Result.success(result);
    }

    @PutMapping
    public Result update(@RequestBody DishDTO dishDTO) {
        log.info("更新：{}", dishDTO);
        dishServiceImpl.update(dishDTO);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(@RequestParam String ids) {
        dishServiceImpl.delete(ids);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status, @RequestParam Integer id) {
        dishServiceImpl.updateStatus(status,id);
        return Result.success();
    }

}
